//## 搭建一个web服务器,针对不同的参数，给予不同的回应,把html文件用异步方式去读取,返回.再去试下用orm框架去操作数据给不同参数返回不同的数据.
//访问链接http://127.0.0.1:8080/food?name=milk

let fs = require('fs');
let http=require('http');
let server=http.createServer(async function(request,response){
    
    console.log(request.method+':'+request.url);

    response.writeHead(200,{'Content_Type':'text/html;charset=utf_8'});

    if(request.url.indexOf("/food")>-1){
            let value=hanshu.chuliurl(request.url);
            let bf=hanshu.readfilefanfa(value);
            response.end(bf);
    
        }
})
// 让服务器监听8080端口:端口不能随意写,2000以上的随你写
server.listen(8080);

console.log('Server is running at http://127.0.0.1:8080/');

let hanshu={
    readfilefanfa:function(value){
        let bf=fs.readFileSync("./html/"+value+".html");
        return bf;
    },
    chuliurl:function(url){
        let arrs = url.split("=");
            let value=arrs[1];
        return value;
    },
}